package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.result.Result;
import com.xuecheng.content.service.TeachpanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TeachPlanController {

    @Autowired
    private TeachpanService teachpanService;


    //查询课程计划
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){

        List<TeachplanDto> teachplanTree = teachpanService.findTeachplanTree(courseId);

        return teachplanTree;
    }


    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto teachplanDto){
        teachpanService.saveTeachplan(teachplanDto);
    }


    @DeleteMapping("/teachplan/{id}")
    public Result deleteTeachplan(@PathVariable Long id){
        Result result = teachpanService.deleteTeachplan(id);
        return result;
    }


    @PostMapping("/teachplan/{type}/{id}")
    public void moveNode(@PathVariable String type,@PathVariable Long id){
        teachpanService.moveNode(type,id);
    }





    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){

        teachpanService.associationMedia(bindTeachplanMediaDto);

    }





}
